package com.yuedao.sender.service1;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import cn.ydx.protobuf.OTIpcDef;

import com.yuedao.sender.model.OrderCreate;
import com.yuedao.sender.model.PositionDriver;
import com.yuedao.sender.model.PositionVehicle;
import com.yuedao.sender.service.PositionDriverRepository;
import com.yuedao.sender.service.PositionVehicleRepository;

@Service
public class PositionService extends BaseService{

	//@Value("${target.positiondriver.url}")
    private String driverURL = "/position/driver";

   // @Value("${target.positionvehicle.url}")
    private String vehicleURL = "/position/vehicle";
    
    
    /**
     * A.7.1  驾驶员定位信息接口
     */
    public String sendPositionDriver(List<PositionDriver> pdList){
    	
        if(pdList.size() > 0){
            OTIpcDef.OTIpc.Builder builder = OTIpcDef.OTIpc.newBuilder().setCompanyId(
                    companyId).setSource(companySource).setIPCType(
                    OTIpcDef.IpcType.positionDriver);
            for(PositionDriver pd:pdList){

                builder.addPositionDriver(PositionDriver.convert(pd));
            }
            OTIpcDef.OTIpc otIpc = builder.build();

            return super.compressAndSend(driverURL, otIpc);
        }
            return null;
    }

    /**
     * A.7.2  车辆定位信息接口
     */
    public String sendPositionVehicle(List<PositionVehicle> pvList){
    	
        if(pvList.size() > 0){
            OTIpcDef.OTIpc.Builder builder = OTIpcDef.OTIpc.newBuilder().setCompanyId(
                    companyId).setSource(companySource).setIPCType(
                    OTIpcDef.IpcType.positionVehicle);
            for(PositionVehicle pv:pvList){


                builder.addPositionVehicle(PositionVehicle.convert(pv));
            }
            OTIpcDef.OTIpc otIpc = builder.build();
            return super.compressAndSend(vehicleURL, otIpc);
        }
            return null;
    }
    
	
}
